package com.situ.store.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.situ.store.entity.Goods;
import com.situ.store.service.GoodsService;
import com.situ.store.service.impl.GoodsServiceImpl;
import com.situ.store.util.BaseController;
import com.situ.store.vo.LayuiTableVO;

@WebServlet("/goods")
public class GoodsController extends BaseController {
	private static final long serialVersionUID = 1L;
	GoodsService ser = new GoodsServiceImpl();

	// 货物主页
	public void page(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.getRequestDispatcher("/WEB-INF/goods.jsp").forward(req, resp);
	}

	// 删除货物
	public void del(Integer id) throws IOException {
		ser.del(id);
	}

	// 修改货物信息
	public Goods edit(Integer id) throws IOException {
		return ser.selectById(id);
	}

	// 保存或编辑
	public void save(Goods goods) throws IOException {
		ser.save(goods);
	}

	// 查询货物信息
	public LayuiTableVO goodsList(Integer page, Integer limit, String keyword1, String keyword2) throws IOException {
		keyword1 = keyword1 == null ? "" : keyword1;
		keyword2 = keyword2 == null ? "" : keyword2;
		List<Goods> list = ser.selectAll(page, limit, keyword1, keyword2);
		LayuiTableVO vo = new LayuiTableVO();
		vo.setCode(0);
		vo.setData(list);
		vo.setCount(ser.count(keyword1, keyword2)); // 统计具体几条
		return vo;
	}

}
